def generate_jwt_token(user):
    from rest_framework_jwt.serializers import api_settings
    jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
    jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
    payload = jwt_payload_handler(user)
    token = jwt_encode_handler(payload)
    user.token = token
    return user


def jwt_response_payload_handler(token, user=None, request=None):

    return {
        'token': token,
        'mobile': user.mobile,
        'id': user.id,
        'avatar': user.avatar,
        'username': user.username
    }
